﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for Baza
/// </summary>
public class Baza
{
    private string errorMessage;
	
    public Baza()
	{
        errorMessage = "";
	}

    public SqlConnection Konekcija()
    {
        SqlConnection konekcija = new SqlConnection();
        konekcija.ConnectionString = ConfigurationManager.ConnectionStrings["mojaKonekcija"].ConnectionString;
        return konekcija;
    }

    public DataSet Zemi(string command, string table)
    {
        SqlConnection konekcija = Konekcija();
        SqlCommand komanda = new SqlCommand();
        komanda.Connection = konekcija;
        komanda.CommandText = command;

        SqlDataAdapter da = new SqlDataAdapter(komanda);
        DataSet ds = new DataSet();
        try
        {
            konekcija.Open();
            da.Fill(ds, table);
        }
        catch (Exception err)
        {
            errorMessage = err.Message;
        }

        finally
        {
            konekcija.Close();
        }
        return ds;
    }

    public void Update(string sqlString)
    {
        SqlConnection konekcija = Konekcija();
        SqlCommand komanda = new SqlCommand();
        komanda.Connection = konekcija;
        komanda.CommandText = sqlString;

        SqlDataAdapter da = new SqlDataAdapter(komanda);
        DataSet ds = new DataSet();
        try
        {
            konekcija.Open();
            komanda.ExecuteNonQuery();
        }
        catch (Exception err)
        {
            errorMessage = err.Message;
        }

        finally
        {
            konekcija.Close();
        }
        
    }
}